#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "visa.h"
#include "visatype.h"
#include  "vpptype.h"
#include <QSettings>
#include <QMessageBox>
#include <QThread>
#include "link/ModBusTcpWorker.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    // 定义枚举
    enum WaveForm {
        SINE = 1,
        SQUARE,
        RAMP,
        PULSE,
        NOISE,
        ARB,
        HARMONIC,
        NONE
    };
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_btn_Connect_clicked();
    void on_btn_Write_clicked();

    void on_btn_Sine_clicked();

    void on_btn_Square_clicked();

    void on_btn_Ramp_clicked();

    void on_btn_Pulse_clicked();

    void on_btn_Noise_clicked();

    void on_btn_Arb_clicked();

    void on_btn_Sine_2_clicked();

    void on_btn_Square_2_clicked();

    void on_btn_Ramp_2_clicked();

    void on_btn_Pulse_2_clicked();

    void on_btn_Noise_2_clicked();

    void on_btn_Arb_2_clicked();

    void on_btn_Hormonic_2_clicked();

    void on_btn_Hormonic_clicked();

    void on_btn_Frequency_clicked();

    void on_btn_Amplitude_clicked();



    void on_btn_Frequency_2_clicked();

    void on_btn_UNIT_clicked();

    void on_btn_UNIT_2_clicked();

    void on_btn_Offset_clicked();
    void on_btn_Offset_2_clicked();

    void on_btn_OutPutOn_clicked();

    void on_btn_OutPutOff_clicked();

    void on_btn_OutPutOn_2_clicked();

    void on_btn_OutPutOff_2_clicked();

    void on_btn_Impedance_clicked();

    void on_btn_Impedance_2_clicked();

signals:
    void sig_SetProNameDevType(QString proName,int DevType);
    void sig_SetIPPort(QString address,short port);
    void sig_SetReadStartAddressAndRegisterCount(QList<int> startAddress, QList<int> registerCount,int RegisterType);
    void sig_SetWriteStartAddressAndRegisterCount(int startAddress, int registerCount,QList<quint16> data);
    void sig_ConnectionAndLoopReadRegister(bool start);

    void sig_AddWriteQueue(WriteData* data);   //增加写消息队列的数据
public slots:
    void  slot_readBoolData(int MsgId,QList<bool> data);  //发送解析后bool数据
    void  slot_readfloatData(int MsgId,QList<float> data);  //发送解析后bool数据
    void slot_ConnectionState(bool isConnectionState);

    void slot_WriteDataQueueFinish();//写队列完成

private slots:
    void timeoutWatchDog();

    void on_btn_Inc_clicked(bool checked);

private:
    void checkConnected();
    QStringList GenerateSwtichWaveFormCommand(WaveForm waveForm,int chNum = 1);//生成波形切换的指令和返回指令
    void setWaveForm(QString ResponseStr,int chNum = 1);//设置每一个通道的波形枚举记录用
    QString setSCPICommand(QString sendCommand,QString RespCommand);//发送指令和接收的指令

    Ui::MainWindow *ui;
    ViSession defaultRM, vi;
    ViStatus status;
    //ViChar buffer[256];
    bool isConnect;

    QSettings* m_Settings;
    QMessageBox msgBox;

    WaveForm m_WaveForm_CH1;//通道1的波形
    WaveForm m_WaveForm_CH2;//通道2的波形

    QThread* m_Thread;
    ModBusTcpWorker* m_ModBusTcpWorker;

    QTimer *m_timer;//定时器

};
#endif // MAINWINDOW_H
